<template>
  <!-- 电子文书 -->
  <view class="root">
    <view class="textVer textBooks">
      <view class="books-content">
        <view class="books-topic">
          <view>{{ textDetail.policeAgencyName }}</view>
          <view>责令整改通知书</view>
          <view>
            {{textDetail.postShopName}}行罚决字 【{{ fullYear }}】
            第{{ textDetail.orderNo }}号
          </view>
        </view>

        <view class="books-article">
          <view class="artTwo">
            <text class="article-con" style="color: #000000">
              {{ textDetail.companyName }}：
            </text>
          </view>

          <view class="artTwo">
            <text class="article-title">
              根据 《{{ textDetail.industryLegalBasis }}》的规定，我所于
              <text class="article-con">{{
              moment(detail.checkTime).format("YYYY")
            }}</text>年
              <text class="article-con">
                {{ moment(detail.checkTime).format("MM") }} </text>月
              <text class="article-con">
                {{ moment(detail.checkTime).format("DD") }} </text>日对你单位(场所)进行常规检查,发现你单位(场所)

              <text class="article-con" v-for="(item, index) in unqualifiedList" :key="index">
                <block>
                  {{ item.examineCategoryName }}存在下列第{{
                  item.unqualifieds.map(obj => obj.sortOrder).join("、")
                }}项的违法行为，
                </block>
              </text>
              现责令改正:
            </text>
          </view>

          <view class="artTwo" v-for="(item, i) in examineIdItems" :key="item.id" style="text-indent: 0">
            <text class="article-title" style="font-weight: bold">
              {{ item.examineCategoryName }}
            </text>

            <view v-for="(afwe, index) in item.inspectionItemsSonVos" :key="afwe.sortOrder" class="article-title"
              :class="radiovalue[i][index].value == 0 ? 'colorRed' : ''">
              <image :src="
                radiovalue[i][index].value == 0
                  ? baseImgUrl + 'square_icon2.png'
                  : baseImgUrl + 'square_icon.png'
              " mode="aspectFill" class="squareImg"></image>
              {{ afwe.sortOrder }}.{{ afwe.industryExamineDetailName }}
            </view>
          </view>

          <view class="artTwo">
            <text class="article-title">
              对上述检查不合格项，责令你单位(场所)于
              <text class="article-con">{{
              moment(routerParams.penaltyEndTime).format("YYYY")
            }}</text>年
              <text class="article-con">
                {{ moment(routerParams.penaltyEndTime).format("MM") }} </text>月
              <text class="article-con">
                {{ moment(routerParams.penaltyEndTime).format("DD") }} </text>日前改正。
            </text>
          </view>

          <view class="artTwo">
            <text class="article-title">
              改正期间，你单位(场所)应当采取措施，确保消防安全，对消防安全违法行为，将依法予以处罚。
            </text>
          </view>

          <view class="seal-person">
            <view>
              <view class="artTwo">
                <text class="article-title"> 被检查单位(场所)签收: </text>
                <view>
                  <image :src="imgPrefix + detail.principalSignatureUrl" mode="aspectFill" class="prinImg"></image>
                </view>
              </view>
            </view>
            <view class="stampTime">
              <image :src="imgPrefix + textDetail.areaElectronicSignature" mode="aspectFill"></image>

              <view class="poView">
                <view class="poName" style="padding-bottom: 20rpx">
                  派出所公章
                </view>
                <view class="poName">
                  {{ formatters(textDetail.checkTime, "wordDay") }}
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view class="bottom-wrapper">
      <u-button class="custom-style" text="负责人确认并签名" @click="handleCheckDone"
        :custom-style="customSubmitStyleFull"></u-button>
    </view>
  </view>

</template>

<script>
  import {
    electronicRecords
  } from "@/api/goover.js";
  import {
    formatters,
    formattersWord,
    customSubmitStyleFull,
    navTo,
    getOptionsParams,
    isLoading
  } from "@/utils/util.js";
  import moment from "@/utils/moment.js";
  import {
    mapState
  } from 'vuex'
  import {
    inspectElectronicRecords
  } from "../api/api";

  export default {
    name: "textBooks",
    data() {
      return {
        baseImgUrl: this.$baseImgUrl,
        imgPrefix: uni.getStorageSync("imgPrefix"),
        options: {},
        fullYear: new Date().getFullYear(),
        detail: {},
        sortOrderNum: [], //  记录第几项违法行为
        checkCategoryInfoListNum: [], // 记录那些大类中有不合格项
        checkCategoryInfoList: [],
        customSubmitStyleFull,
        routerParams: {},
        textDetail: {}
      };
    },
    computed: {
      ...mapState(['radiovalue', 'evidenceList', 'examineIdItems']),
      unqualifiedList() {
        let result = []
        this.radiovalue.forEach((outerItem, i) => {
          // 找出不合格的
          let outerObj = {
            examineCategoryName: this.examineIdItems[i].examineCategoryName,
            unqualifieds: []
          }
          outerItem.forEach((item, index) => {
            // 
            if (item.value === 0) {
              let innerObj = {
                // 
                // 证据索引
                outerIndex: i,
                innerIndex: index,
                // 检查项内容
                ...this.examineIdItems[i]['inspectionItemsSonVos'][index]
                // 
              }
              outerObj.unqualifieds.push(innerObj)
            }
          })
          if (outerObj.unqualifieds.length) {
            result.push(outerObj)
          }
        })
        return result
      }
    },
    onLoad(options) {
      this.options = options;
      this.routerParams = getOptionsParams(options)
      this.detail = this.routerParams
      this.initData()
    },
    methods: {
      formatters,
      formattersWord,
      moment,
      handleCheckDone() {
        navTo({
          url: '/venueInspection/checkDone',
          params: {
            ...this.routerParams,
            source: 'no-pass'
          }
        })
      },
      initData() {
        let params = {
          ...this.routerParams,
          penaltyEndTime: this.routerParams.penaltyEndTime ? new Date(this.routerParams.penaltyEndTime).getTime() :
            this
            .routerParams.penaltyEndTime,
          // "industryExamineName": "常规检查",
          // "rectificationType": "1",
          // "penaltyEndTime": "1733414399000",
          // "descriptionOfViolation": "是否不存在私拉电线行为并且不存在其它用电安全的隐患;",
          // "detailId": "1825365182278500353"
        }
        // 表示从复查页面过来的
        if (this.routerParams.action === 'recheck') {
          params = {
            ...this.routerParams.paramsInfo,
            penaltyEndTime: this.routerParams.paramsInfo.penaltyEndTime ? new Date(this.routerParams.paramsInfo
                .penaltyEndTime).getTime() : this
              .routerParams.paramsInfo.penaltyEndTime,
          }
        }
        isLoading(true)
        inspectElectronicRecords(params).then((res) => {
            this.textDetail = res.result
            if (this.routerParams.action == 'recheck') {
              this.$set(this.detail, 'checkTime', res.result.checkTime)
            }
          })
          .finally(() => {
            isLoading(false)
          })
      }
    },
  };
</script>

<style>

</style>
<style lang="scss" scoped>
  .root {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;

    .textBooks {
      padding: 20rpx 0;
      flex: 1;
      overflow: auto;

      .books-content {
        margin: 0 15rpx;
        min-height: 95vh;
        border: 1px solid #830707;

        .books-topic {
          color: #9e520a;
          text-align: center;
          font-weight: 500;
          line-height: 60rpx;

          view:nth-of-type(1) {
            margin-top: 20rpx;
            font-size: 28rpx;
          }

          view:nth-of-type(2) {
            font-size: 48rpx;
            font-weight: 700;
          }

          view:nth-of-type(3) {
            color: #232222;
            font-size: 24rpx;
          }
        }

        .books-article {
          margin-top: 20rpx;
          padding: 0 20rpx;
          color: #848484;
          font-size: 26rpx;
          font-weight: 500;

          .artTwo {
            text-indent: 2em;
            line-height: 60rpx;

            .article-title {
              color: #000000;
              font-size: 28rpx;

              .squareImg {
                margin-right: 10rpx;
                width: 22rpx;
                height: 22rpx;
              }
            }

            .prinImg {
              width: 205rpx;
              height: 99rpx;
            }

            .colorRed {
              color: #ee1c1c;
            }

            .article-con {
              padding-bottom: 2px;
              color: #333333;
              border-bottom: 1px solid #830707;
            }
          }

          .seal-person {
            display: flex;
            justify-content: space-between;
            position: relative;
            margin-top: 30rpx;

            .stampTime {
              min-width: 190rpx;

              image {
                width: 180rpx;
                height: 180rpx;
              }

              .poView {
                position: absolute;
                top: 20rpx;

                .poName {
                  color: #000000;
                  font-size: 24rpx;
                  text-align: right;
                }
              }
            }
          }
        }
      }
    }

    .bottom-wrapper {
      width: 100%;
      height: 120rpx;
      background: #FFFFFF;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
</style>